package com.Zuoye;

import java.util.Scanner;

/**
 * description 暂无描述
 * author 毛舒锐
 * time 2023/3/11 19:21
 */
public class Zuoye {
    public static void main(String[] args) {
        //定义存放身份数据容器
        String[] nameArr = new String[1000];
        String[] idCardArr = new String[1000];
        String[] genderArr = new String[1000];
        String[] addressArr = new String[1000];
        //界面显示
        for (int index = 0; ; ) {
            System.out.println("*****请输入如下选项:*****");
            System.out.println("\t1.信息录入");
            System.out.println("\t2.信息查询");
            System.out.println("\t3.信息修改");
            System.out.println("\t4.信息删除");
            System.out.println("\t5.退出");
            System.out.println("开始录入公民信息>>>");
            Scanner sc = new Scanner(System.in);
            System.out.print("请选择:");
            int num = sc.nextInt();
            //键盘录入进入不同的模块
            switch (num) {
                case 1:
                    System.out.print("(1)请输入姓名:");
                    String name = sc.next();
                    //判断身份证号是否正确
                    System.out.print("(2)请输入身份证号:");
                    String idCard = sc.next();
                    if (idCard.length() != 18) {
                        System.out.println("您输入的有误，请重新输入!!!");
                        break;
                    }
                    //判断性别是否输入正确
                    System.out.print("(3)请输入性别(1男0女):");
                    String gender = sc.next();
                    if (!(gender.equals("1") || gender.equals("0"))) {
                        System.out.println("您输入有误!!!");
                        break;
                    }
                    System.out.print("(4)请输入地址:");
                    String address = sc.next();
                    System.out.println("录入成功!");
                    //将用户的信息保存起来
                    nameArr[index] = name;
                    idCardArr[index] = idCard;
                    genderArr[index] = gender.equals("0") ? "女" : "男";
                    addressArr[index] = address;
                    index++;
                    System.out.println();
                    break;
                case 2:
                    System.out.println("所有人信息列表如下:");
                    //展示所有录入的人员信息
                    for (int i = 0; i < index; i++) {
                        System.out.println(nameArr[i] + "\t" + idCardArr[i] + "\t" + genderArr[i] + "\t" + addressArr[i]);
                    }
                    System.out.println();
                    break;
                case 3:
                    System.out.println("信息修改:");
                    System.out.print("请输入需要修改人身份证:");
                    String idCard1 = sc.next();
                    //判断身份证号是否存在
                    int n = -1;
                    for (int i = 0; i < index; i++) {
                        if (idCard1.equals(idCardArr[i])) {
                            n = i;
                        }
                        if (n == -1) {
                            System.out.println("此身份证号不存在!");
                            break;
                        }
                        System.out.println("开始信息修改:");
                        System.out.print("请输入姓名:");
                        String name1 = sc.next();
                        System.out.print("请输入性别:");
                        String gender1 = sc.next();
                        //判断性别输入是否有误
                        if (!(gender1.equals("0") || gender1.equals("1"))) {
                            System.out.println("您输入的性别有误!!");
                            break;
                        }
                        System.out.print("请输入年龄:");
                        String address1 = sc.next();
                        System.out.println("修改成功");
                        //将修改后的信息存入数组中
                        nameArr[n] = name1;
                        genderArr[n] = gender1;
                        addressArr[n] = address1;
                        break;
                    }
                case 4:
                    System.out.println("开始删除信息:");
                    System.out.print("请输入要删除人身份证号:");
                    String idCard2 = sc.next();
                    //判断身份证号是否存在
                    int e = -1;
                    for (int i = 0; i < index; i++) {
                        if (idCard2.equals(idCardArr[i])) {
                            e = i;
                        }
                        if (e == -1) {
                            System.out.println("此身份证号不存在!");
                            break;
                        }
                        for (int j = e+1; j <index ; j++) {
                            nameArr[e] = nameArr[j];
                            idCardArr[e] = idCardArr[j];
                            genderArr[e] = genderArr[j];
                            addressArr[e] = addressArr[j];
                        }
                        System.out.println("删除成功!!");
                        index--;
                        System.out.println("自动退出系统!!");
                        System.exit(0);
                        break;
                    }
            }
        }
    }
}
